-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[flang] Fix crash resolving interface procedure type. #162205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
When generic interface name shadows specific, bypass to specific procedure while resolving its type.
@llvm/pr-subscribers-flang-semantics Author: Valery Dmitriev (valerydmit) ChangesWhen generic interface name shadows specific, bypass to specific procedure while resolving its type. Full diff: https://github.com/llvm/llvm-project/pull/162205.diff 3 Files Affected:
diff --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h
index 975423b32da73..98e2a5fe88da4 100644
--- a/flang/include/flang/Semantics/symbol.h
+++ b/flang/include/flang/Semantics/symbol.h
@@ -1126,6 +1126,9 @@ inline const DeclTypeSpec *Symbol::GetTypeImpl(int depth) const {
[&](const HostAssocDetails &x) {
return x.symbol().GetTypeImpl(depth);
},
+ [&](const GenericDetails &x) {
+ return x.specific() ? x.specific()->GetTypeImpl(depth) : nullptr;
+ },
[](const auto &) -> const DeclTypeSpec * { return nullptr; },
},
details_);
diff --git a/flang/test/Semantics/Inputs/generic-shadows-specific-a.f90 b/flang/test/Semantics/Inputs/generic-shadows-specific-a.f90
new file mode 100644
index 0000000000000..bf3c6d464c7dd
--- /dev/null
+++ b/flang/test/Semantics/Inputs/generic-shadows-specific-a.f90
@@ -0,0 +1,21 @@
+! these modules must be read from module files
+module m1
+ interface f ! reference must be to generic
+ module procedure f ! must have same name as generic interface
+ end interface
+ contains
+ character function f() ! must be character
+ f = 'q'
+ end
+end
+module m2
+ use m1
+end
+module m3
+ use m2 ! must be m2, not m1
+ contains
+ subroutine mustExist() ! not called, but must exist
+ character x
+ x = f()
+ end
+end
diff --git a/flang/test/Semantics/generic-shadows-specific-b.f90 b/flang/test/Semantics/generic-shadows-specific-b.f90
new file mode 100644
index 0000000000000..d1dcefc7499a0
--- /dev/null
+++ b/flang/test/Semantics/generic-shadows-specific-b.f90
@@ -0,0 +1,13 @@
+! Check that expected code produced with no crash.
+subroutine reproducer()
+ use m2
+ use m3
+ character x
+ x = f()
+end
+
+! RUN: %flang_fc1 -fsyntax-only %S/Inputs/generic-shadows-specific-a.f90
+! RUN: bbc -emit-fir -o - %s | FileCheck %s
+
+! CHECK-LABEL: func.func @_QPreproducer
+! CHECK: fir.call @_QMm1Pf
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit on the test. The fix makes sense to me, but please wait for @klausler before merging.
! Check that expected code produced with no crash. | ||
subroutine reproducer() | ||
use m2 | ||
use m3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test failure you are seeing in the windows bot most likely comes from module file clashes.
LIT tests are run in parallel in the same folder.
Any tests that relies on writing and then reading a module file should be run in a temporary directory to avoid any troubles (m
, m1
, m2
... are quite common name. It is OK when the test is a single compilation unit, but when doing several steps, the related module file will very likely be overridden).
You can use:
! RUN: rm -rf %t && mkdir -p %t
Also, as a nit, I think tests using -emit-fir/hlfir
should live in test/Lower (there are a few precedent, but I do not think it is best practice). You can move it in test/Lower (there is no Input directory there, but you can achieve the same by making it single file test by using macros around the different steps of the compilation (see ./Semantics/modfile71.F90
for an example).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way to allow tests with module files to run in parallel is to include the name of the test in the names of the modules.
When generic interface name shadows specific, bypass to specific procedure while resolving its type.